<?php
header('Content-type:text/json');

// A list of permitted file extensions
$allowed = array('png', 'jpg', 'gif','zip','pdf','txt');

if(isset($_FILES['upl']) && $_FILES['upl']['error'] == 0){

	$extension = pathinfo($_FILES['upl']['name'], PATHINFO_EXTENSION);

	if(!in_array(strtolower($extension), $allowed)){
		echo '{"status":"error"}';
		exit;
	}
	
	$dir = dirname(__FILE__);
	$fileName = $dir.'/uploads/'.$_FILES['upl']['name'];

	if(move_uploaded_file($_FILES['upl']['tmp_name'], $fileName)){
		$result = array(
			'status'=>"success",
			'fileName'=>$fileName
		);
		echo json_encode($result);
		exit;
	}
}

echo '{"status":"error"}';
exit;